﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApiVersionControl.Models.Untity
{
    public class APIModel
    {
        public int code;

        public object data { get; set; }

        public string msg { get; set; }

        public static ActionResult success(object data, string msg = "")
        {
            return new JsonResult
            {
                Data = new APIModel
                {
                    code = 1,
                    data = data,
                    msg = msg
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

        public static ActionResult JsonSuccess(object data, string msg = "")
        {
            return new JsonResult
            {
                Data = new APIModel
                {
                    code = 1,
                    data = data,
                    msg = msg
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

        public static ActionResult error(string msg, object data = null)
        {
            return new JsonResult
            {
                Data = new APIModel
                {
                    code = -1,
                    data = data,
                    msg = msg
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

        public static ActionResult JsonError(object data, string msg = "")
        {
            return new JsonResult
            {
                Data = new APIModel
                {
                    code = 1,
                    data = data,
                    msg = msg
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

        public static ActionResult Bind(string msg, object data)
        {
            return new JsonResult
            {
                Data = new APIModel
                {
                    code = -8888,
                    msg = msg,
                    data = data
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

        public static ActionResult ParamError(string msg)
        {
            return new JsonResult
            {
                Data = new APIModel
                {
                    code = -9999,
                    data = null,
                    msg = msg
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

    }
}